import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-02-23
 * Time: 12:07
 */
public class test1 {
    /**
     * LeetCode 1046  最后一块石头的重量
     */

    public int lastStoneWeight(int[] stones) {
        // 大根堆：大的放在上面
        PriorityQueue<Integer> heap = new PriorityQueue<>((a, b) -> b-a);
        // 放进堆里面
        for(int x:stones){
            heap.offer(x);
        }
        // 模拟
        while(heap.size()>1){
            int a = heap.poll();
            int b = heap.poll();
            if(a>b){
                int x = a-b;
                heap.offer(x);
            }
        }
        return heap.isEmpty()?0:heap.peek();
    }
}
